package com.qfedu.edu.entrypoint;

import com.qfedu.edu.enum1.ResponseCode;
import com.qfedu.edu.result.R;
import com.qfedu.edu.utils.HttpResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Slf4j
@Component
public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        log.info("没有权限访问这个方法...");
        R error = R.error(ResponseCode.NOT_VISITOR);
        HttpResponseUtils.sendResponse(response, error);
    }
}
